{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "WgDTg6YKyYDA"
   },
   "source": [
    "# 9.13 实战Kaggle比赛：狗的品种识别（ImageNet Dogs）\n",
    "\n",
    "\n",
    "我们将在本节动手实战Kaggle比赛中的狗的品种识别问题。该比赛的网页地址是 https://www.kaggle.com/c/dog-breed-identification 。\n",
    "\n",
    "在这个比赛中，将识别120类不同品种的狗。这个比赛的数据集实际上是著名的ImageNet的子集数据集。和上一节的CIFAR-10数据集中的图像不同，ImageNet数据集中的图像更高更宽，且尺寸不一。\n",
    "\n",
    "图9.17展示了该比赛的网页信息。为了便于提交结果，请先在Kaggle网站上注册账号。\n",
    "\n",
    "![狗的品种识别比赛的网页信息。比赛数据集可通过点击“Data”标签获取](http://zh.d2l.ai/_images/kaggle-dog.png)\n",
    "\n",
    "首先，导入比赛所需的包或模块。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "4n4u8eLHyiDb"
   },
   "outputs": [],
   "source": [
    "# Install TensorFlow\n",
    "try:\n",
    "  # %tensorflow_version only exists in Colab.\n",
    "  %tensorflow_version 2.x\n",
    "except Exception:\n",
    "    pass\n",
    "import tensorflow as tf\n",
    "from tensorflow import keras\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "import os\n",
    "import shutil\n",
    "import collections\n",
    "import math\n",
    "import random"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "EF8TxdtpzCwu"
   },
   "source": [
    "## 9.13.1 获取和整理数据集\n",
    "\n",
    "\n",
    "比赛数据分为训练集和测试集。训练集包含了10,222张图像，测试集包含了10,357张图像。两个数据集中的图像格式都是JPEG。这些图像都含有RGB三个通道（彩色），高和宽的大小不一。训练集中狗的类别共有120种，如拉布拉多、贵宾、腊肠、萨摩耶、哈士奇、吉娃娃和约克夏等。\n",
    "\n",
    "\n",
    "### 9.13.1.1 下载数据集\n",
    "\n",
    "登录Kaggle后，我们可以点击图9.17所示的狗的品种识别比赛网页上的“Data”标签，并分别下载训练数据集train.zip、测试数据集test.zip和训练数据集标签label.csv.zip。下载完成后，将它们分别存放在以下3个路径：\n",
    "\n",
    "* ../data/kaggle_dog/train.zip；\n",
    "* ../data/kaggle_dog/test.zip；\n",
    "* ../data/kaggle_dog/labels.csv.zip。\n",
    "\n",
    "\n",
    "为方便快速上手，我们提供了上述数据集的小规模采样train_valid_test_tiny.zip。如果要使用上述Kaggle比赛的完整数据集，还需要把下面`demo`变量改为`False`。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "jidE4KzWzHOp"
   },
   "outputs": [],
   "source": [
    "# 如果使用下载的Kaggle比赛的完整数据集，把demo变量改为False\n",
    "import zipfile\n",
    "demo = True\n",
    "data_dir = '../../data/kaggle_dog'\n",
    "if demo:\n",
    "    zipfiles = ['train_valid_test_tiny.zip']\n",
    "else:\n",
    "    zipfiles = ['train.zip', 'test.zip', 'labels.csv.zip']\n",
    "for f in zipfiles:\n",
    "    with zipfile.ZipFile(data_dir + '/' + f, 'r') as z:\n",
    "        z.extractall(data_dir)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "8RRT72qgM22J"
   },
   "source": [
    "### 9.13.1.2 整理数据集\n",
    "\n",
    "我们定义下面的`reorg_train_valid`函数来从Kaggle比赛的完整原始训练集中切分出验证集。该函数中的参数`valid_ratio`指验证集中每类狗的样本数与原始训练集中数量最少一类的狗的样本数（66）之比。经过整理后，同一类狗的图像将被放在同一个文件夹下，便于稍后读取。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "oTumrVwrM1t-"
   },
   "outputs": [],
   "source": [
    "def reorg_train_valid(data_dir, train_dir, input_dir, valid_ratio, idx_label):\n",
    "    # 训练集中数量最少一类的狗的样本数\n",
    "    min_n_train_per_label = (\n",
    "        collections.Counter(idx_label.values()).most_common()[:-2:-1][0][1])\n",
    "    # 验证集中每类狗的样本数\n",
    "    n_valid_per_label = math.floor(min_n_train_per_label * valid_ratio)\n",
    "    label_count = {}\n",
    "    for train_file in os.listdir(os.path.join(data_dir, train_dir)):\n",
    "        idx = train_file.split('.')[0]\n",
    "        label = idx_label[idx]\n",
    "        d2l.mkdir_if_not_exist([data_dir, input_dir, 'train_valid', label])\n",
    "        shutil.copy(os.path.join(data_dir, train_dir, train_file),\n",
    "                    os.path.join(data_dir, input_dir, 'train_valid', label))\n",
    "        if label not in label_count or label_count[label] < n_valid_per_label:\n",
    "            d2l.mkdir_if_not_exist([data_dir, input_dir, 'valid', label])\n",
    "            shutil.copy(os.path.join(data_dir, train_dir, train_file),\n",
    "                        os.path.join(data_dir, input_dir, 'valid', label))\n",
    "            label_count[label] = label_count.get(label, 0) + 1\n",
    "        else:\n",
    "            d2l.mkdir_if_not_exist([data_dir, input_dir, 'train', label])\n",
    "            shutil.copy(os.path.join(data_dir, train_dir, train_file),\n",
    "                        os.path.join(data_dir, input_dir, 'train', label))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "an27u7KuTZSp"
   },
   "source": [
    "下面的`reorg_dog_data`函数用来读取训练数据标签、切分验证集并整理测试集。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "7e4ua2C90U4v"
   },
   "outputs": [],
   "source": [
    "def reorg_dog_data(data_dir, label_file, train_dir, test_dir, input_dir,\n",
    "                   valid_ratio):\n",
    "    # 读取训练数据标签\n",
    "    with open(os.path.join(data_dir, label_file), 'r') as f:\n",
    "        # 跳过文件头行（栏名称）\n",
    "        lines = f.readlines()[1:]\n",
    "        tokens = [l.rstrip().split(',') for l in lines]\n",
    "        idx_label = dict(((idx, label) for idx, label in tokens))\n",
    "    reorg_train_valid(data_dir, train_dir, input_dir, valid_ratio, idx_label)\n",
    "    # 整理测试集\n",
    "    d2l.mkdir_if_not_exist([data_dir, input_dir, 'test', 'unknown'])\n",
    "    for test_file in os.listdir(os.path.join(data_dir, test_dir)):\n",
    "        shutil.copy(os.path.join(data_dir, test_dir, test_file),\n",
    "                    os.path.join(data_dir, input_dir, 'test', 'unknown'))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "fCyjRqjfUNzn"
   },
   "source": [
    "因为我们在这里使用了小数据集，所以将批量大小设为1。在实际训练和测试时，我们应使用Kaggle比赛的完整数据集并调用`reorg_dog_data`函数来整理数据集。相应地，我们也需要将批量大小`batch_size`设为一个较大的整数，如128。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "Bp8x0AAiUOy9"
   },
   "outputs": [],
   "source": [
    "if demo:\n",
    "    # 注意，此处使用小数据集并将批量大小相应设小。使用Kaggle比赛的完整数据集时可设批量大小\n",
    "    # 为较大整数\n",
    "    input_dir, batch_size = 'train_valid_test_tiny', 1\n",
    "else:\n",
    "    label_file, train_dir, test_dir = 'labels.csv', 'train', 'test'\n",
    "    input_dir, batch_size, valid_ratio = 'train_valid_test', 128, 0.1\n",
    "    reorg_dog_data(data_dir, label_file, train_dir, test_dir, input_dir,\n",
    "                   valid_ratio)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "TKyaVlvzUgoG"
   },
   "source": [
    "## 9.13.2 图像增广\n",
    "\n",
    "本节比赛的图像尺寸比上一节中的更大。这里列举了更多可能有用的图像增广操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "1YbY0SGCUl54"
   },
   "outputs": [],
   "source": [
    "def transform_train(imgpath,label):\n",
    "    # 随机对图像裁剪出面积为原图像面积0.08~1倍、且高和宽之比在3/4~4/3的图像，再放缩为高和\n",
    "    # 宽均为224像素的新图像\n",
    "    feature=tf.io.read_file(imgpath)\n",
    "    feature = tf.image.decode_jpeg(feature,channels=3)\n",
    "    feature = tf.image.resize(feature, size=[400, 400])\n",
    "    seed=random.randint(8,100)/100\n",
    "    feature = tf.image.random_crop(feature, size=[int(seed*feature.shape[0]), int(seed*feature.shape[1]), 3])\n",
    "    feature = tf.image.resize(feature, size=[224, 224])\n",
    "    feature = tf.image.random_flip_left_right(feature)\n",
    "    feature = tf.image.random_flip_up_down(feature)\n",
    "    # 标准化\n",
    "    feature = tf.divide(feature, 255.)\n",
    "    # 正则化\n",
    "    mean = tf.convert_to_tensor([0.485, 0.456, 0.406])\n",
    "    std = tf.convert_to_tensor([0.229, 0.224, 0.225])\n",
    "    feature = tf.divide(tf.subtract(feature, mean), std)\n",
    "    #feature = tf.image.per_image_standardization(feature)\n",
    "    #print(feature,label)\n",
    "    return tf.image.convert_image_dtype(feature, tf.float32),label"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "6s0Qd169AzCk"
   },
   "source": [
    "测试时，我们只使用确定性的图像预处理操作。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "TnzC_P2QAsYH"
   },
   "outputs": [],
   "source": [
    "def transform_test(imgpath,label):\n",
    "    feature=tf.io.read_file(imgpath)\n",
    "    feature = tf.image.decode_jpeg(feature,channels=3)\n",
    "    feature = tf.image.resize(feature, [224, 224])\n",
    "    feature = tf.divide(feature, 255.)\n",
    "    # feature = tf.image.per_image_standardization(feature)\n",
    "    mean = tf.convert_to_tensor([0.485, 0.456, 0.406])\n",
    "    std = tf.convert_to_tensor([0.229, 0.224, 0.225])\n",
    "    feature = tf.divide(tf.subtract(feature, mean), std)\n",
    "    return feature,label"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "Y0wvR06VBnoO"
   },
   "source": [
    "## 9.12.3 读取数据集\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "dRIQk7K-7r7D"
   },
   "source": [
    "获取所有图片path和label"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 51
    },
    "colab_type": "code",
    "id": "9bYwOlzV4wd7",
    "outputId": "341d1ebb-1104-437e-9ca3-fecd753d6f4e"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First 10 images indices:  [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]\n",
      "First 10 labels indices:  [0, 0, 1, 1, 2, 2, 3, 3, 4, 4]\n"
     ]
    }
   ],
   "source": [
    "import pathlib\n",
    "data_root=\"../../data/kaggle_dog/train_valid_test_tiny\"\n",
    "train_data_root = pathlib.Path(data_root+\"/train\")\n",
    "valid_data_root = pathlib.Path(data_root+\"/valid\")\n",
    "train_valid_data_root = pathlib.Path(data_root+\"/train_valid\")\n",
    "test_data_root = pathlib.Path(data_root+\"/test\")\n",
    "label_names = sorted(item.name for item in train_data_root.glob('*/') if item.is_dir())\n",
    "label_to_index = dict((name, index) for index, name in enumerate(label_names))\n",
    "\n",
    "train_all_image_paths = [str(path) for path in list(train_data_root.glob('*/*'))]\n",
    "valid_all_image_paths = [str(path) for path in list(valid_data_root.glob('*/*'))]\n",
    "train_valid_all_image_paths = [str(path) for path in list(train_valid_data_root.glob('*/*'))]\n",
    "test_all_image_paths = [str(path) for path in list(test_data_root.glob('*/*'))]\n",
    "\n",
    "\n",
    "train_all_image_labels = [label_to_index[pathlib.Path(path).parent.name] for path in train_all_image_paths]\n",
    "valid_all_image_labels = [label_to_index[pathlib.Path(path).parent.name] for path in valid_all_image_paths]\n",
    "train_valid_all_image_labels = [label_to_index[pathlib.Path(path).parent.name] for path in train_valid_all_image_paths]\n",
    "test_all_image_labels = [-1 for i in range(len(test_all_image_paths))]\n",
    "print(\"First 10 images indices: \", train_valid_all_image_labels[:10])\n",
    "print(\"First 10 labels indices: \", train_valid_all_image_labels[:10])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "yvIUCub6F1S-"
   },
   "source": [
    "构建一个 tf.data.Dataset"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "tHbdFJyDFuW-"
   },
   "outputs": [],
   "source": [
    "train_ds = tf.data.Dataset.from_tensor_slices((train_all_image_paths, train_all_image_labels)).map(transform_train).shuffle(len(train_all_image_paths)).batch(batch_size)\n",
    "valid_ds = tf.data.Dataset.from_tensor_slices((valid_all_image_paths, valid_all_image_labels)).map(transform_train).shuffle(len(valid_all_image_paths)).batch(batch_size)\n",
    "train_valid_ds = tf.data.Dataset.from_tensor_slices((train_valid_all_image_paths, train_valid_all_image_labels)).map(transform_train).shuffle(len(train_valid_all_image_paths)).batch(batch_size)\n",
    "test_ds = tf.data.Dataset.from_tensor_slices((test_all_image_paths, test_all_image_labels)).map(transform_test).shuffle(len(test_all_image_paths)).batch(batch_size)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 127,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 34
    },
    "colab_type": "code",
    "id": "GXd2xr8lnJa1",
    "outputId": "594d34da-a809-4aab-c12a-1c460613bb3b"
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<BatchDataset shapes: ((None, 224, 224, 3), (None,)), types: (tf.float32, tf.int32)>"
      ]
     },
     "execution_count": 127,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_ds"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "1dMYo-qYh7-E"
   },
   "source": [
    "## 9.13.4 定义模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 120,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 255
    },
    "colab_type": "code",
    "id": "Fq6o8nEHiAxa",
    "outputId": "27553f9d-31eb-4253-d5fe-b8ad4295805a"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"sequential_2\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "resnet50 (Model)             (None, 7, 7, 2048)        23587712  \n",
      "_________________________________________________________________\n",
      "global_average_pooling2d_2 ( (None, 2048)              0         \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 120)               245880    \n",
      "=================================================================\n",
      "Total params: 23,833,592\n",
      "Trainable params: 23,780,472\n",
      "Non-trainable params: 53,120\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "from tensorflow.keras.applications import ResNet50\n",
    "net=ResNet50(\n",
    "    input_shape=(224, 224, 3),\n",
    "    weights='imagenet',\n",
    "    include_top=False\n",
    ")\n",
    "model = tf.keras.Sequential([\n",
    "    net,\n",
    "    tf.keras.layers.GlobalAveragePooling2D(),\n",
    "    tf.keras.layers.Dense(len(label_names), activation='softmax',dtype=tf.float32)\n",
    "])\n",
    "model.summary()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "sTKCtAXElDqR"
   },
   "source": [
    "## 9.13.5. 定义训练函数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "bD6gFtuvlFp2"
   },
   "outputs": [],
   "source": [
    "lr = 0.1\n",
    "lr_decay = 0.01\n",
    "\n",
    "def scheduler(epoch):\n",
    "    if epoch < 10:\n",
    "        return lr\n",
    "    else:\n",
    "        return lr * tf.math.exp(lr_decay * (10 - epoch))\n",
    "\n",
    "callback = tf.keras.callbacks.LearningRateScheduler(scheduler)\n",
    "\n",
    "model.compile(optimizer=keras.optimizers.SGD(learning_rate=lr, momentum=0.9),\n",
    "        loss='sparse_categorical_crossentropy')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "mtFyY8qvjrGp"
   },
   "source": [
    "## 9.13.6. 训练模型"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 132,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 51
    },
    "colab_type": "code",
    "id": "6Su-Sf8Jj5I_",
    "outputId": "a0c4fb48-0bad-466a-ccdc-6bcee6da6cf4"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "120/120 [==============================] - 105s 879ms/step - loss: 5.2341 - val_loss: 5.6558 - lr: 0.1000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x7fa4cb2daac8>"
      ]
     },
     "execution_count": 132,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.fit(train_ds, epochs=1 , validation_data=valid_ds,  callbacks=[callback])"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "LwsMHEIsx8Ll"
   },
   "source": [
    "## 9.13.7 对测试集分类并在Kaggle提交结果\n",
    "得到一组满意的模型设计和超参数后，我们使用全部训练数据集（含验证集）重新训练模型，并对测试集分类。注意，我们要用刚训练好的输出网络做预测。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 133,
   "metadata": {
    "colab": {
     "base_uri": "https://localhost:8080/",
     "height": 51
    },
    "colab_type": "code",
    "id": "fs11_OqGx5hg",
    "outputId": "76d41bd9-c6a6-4c4e-9a0b-e7b9c1f3b774"
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "240/240 [==============================] - 171s 712ms/step - loss: 5.1725 - lr: 0.1000\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<tensorflow.python.keras.callbacks.History at 0x7fa4ca7937b8>"
      ]
     },
     "execution_count": 133,
     "metadata": {
      "tags": []
     },
     "output_type": "execute_result"
    }
   ],
   "source": [
    "model.compile(optimizer=keras.optimizers.SGD(learning_rate=lr, momentum=0.9),\n",
    "        loss='sparse_categorical_crossentropy')\n",
    "model.fit(train_valid_ds, epochs=1 , callbacks=[callback])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "FmrCyEJw02-E"
   },
   "outputs": [],
   "source": [
    "probabilities=model.predict(test_ds)\n",
    "predictions=np.argmax(probabilities, axis=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 0,
   "metadata": {
    "colab": {},
    "colab_type": "code",
    "id": "zNnp7Wux1PXf"
   },
   "outputs": [],
   "source": [
    "ids = sorted(os.listdir(os.path.join(data_dir, input_dir, 'test/unknown')))\n",
    "with open('submission.csv', 'w') as f:\n",
    "    f.write('id,' + \"preds\"+ '\\n')\n",
    "    for i, output in zip(ids, predictions):\n",
    "        f.write(i.split('.')[0] + ',' + str(output) + '\\n')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {
    "colab_type": "text",
    "id": "CWO6Ix3ky1U4"
   },
   "source": [
    "## 小结\n",
    "\n",
    "* 我们可以使用在ImageNet数据集上预训练的模型抽取特征，并仅训练自定义的小规模输出网络，从而以较小的计算和存储开销对ImageNet的子集数据集做分类。"
   ]
  }
 ],
 "metadata": {
  "colab": {
   "collapsed_sections": [],
   "name": "9.13_kaggle_dog.ipynb",
   "provenance": []
  },
  "hide_input": false,
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  },
  "latex_envs": {
   "LaTeX_envs_menu_present": true,
   "autoclose": true,
   "autocomplete": true,
   "bibliofile": "biblio.bib",
   "cite_by": "apalike",
   "current_citInitial": 1,
   "eqLabelWithNumbers": true,
   "eqNumInitial": 1,
   "hotkeys": {
    "equation": "Ctrl-E",
    "itemize": "Ctrl-I"
   },
   "labels_anchors": false,
   "latex_user_defs": false,
   "report_style_numbering": false,
   "user_envs_cfg": false
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  },
  "varInspector": {
   "cols": {
    "lenName": 16,
    "lenType": 16,
    "lenVar": 40
   },
   "kernels_config": {
    "python": {
     "delete_cmd_postfix": "",
     "delete_cmd_prefix": "del ",
     "library": "var_list.py",
     "varRefreshCmd": "print(var_dic_list())"
    },
    "r": {
     "delete_cmd_postfix": ") ",
     "delete_cmd_prefix": "rm(",
     "library": "var_list.r",
     "varRefreshCmd": "cat(var_dic_list()) "
    }
   },
   "types_to_exclude": [
    "module",
    "function",
    "builtin_function_or_method",
    "instance",
    "_Feature"
   ],
   "window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
